var row =
	{ 
		init : function()
			{
				this.busca = new Ext.form.TextField
			        ({
			            fieldLabel: 'Termo',
			            name: 'data[Busca][termo]',
			            allowBlank: false,
			            width: 580,
			            minLength: 2
			        });
		        
		        this.buttons = new Ext.Panel
					({
						buttonAlign: 'center',
						buttons:
							[
								new Ext.Button
									({
										text: 'Procurar',
							            handler: function()
								            {
												if(formX.form.isValid())
												{
													row.gridX.store.proxy = new Ext.data.HttpProxy
														({
															url: _PHP_.grid.url.data+'?anticache='+Math.random(),
															method: 'POST',
															disableCaching: false
														});																
													row.gridX.store.baseParams =
														{
															termo: row.busca.getValue()
														};
													row.gridX.store.load
														({
															params:
																{
																	limit: 18,
																	offset: 0
																}
														});
												}
												else
												{
													Ext.MessageBox.alert('Erro', 'Por favor preencha os campos indicados.');
												}
											}
							        }),
						        new Ext.Button
							        ({
							            text: 'Limpar',
							            handler: function()
								            {
												formX.form.reset();
											}
							        })
							]
					});	
				
				this.datastore = new Ext.data.GroupingStore
					({
				        reader: new Ext.data.JsonReader
				        	(
						        {
						            root: 'rows',
						            totalProperty: 'total',
						            id: 'id'
						        },
						        [
						            'id',
						            'nome',
						            'group',
						            'area'
						        ]
							),
						remoteSort: true,
				        remoteGroup: true,
				        sortInfo:
				       		{
				       			field: _PHP_.grid.sort.field,
				       			direction: _PHP_.grid.sort.direction
				       		},
			            groupField: 'group',
			            listeners:
			            	{
			            		load: function(records, options)
			            			{
			            				if(records.getTotalCount() < 1)
			            				{
			            					Ext.Msg.alert('Resultado', 'Nenhum item relacionado ao termo foi encontrado.', function()
			            						{
			            							row.gridX.disable();
			            						});
			            				}
			            				else
			            				{
			            					row.gridX.enable();
			            					if(!row.fieldset.isVisible())
			            					{
			            						row.fieldset.setVisible(true);
			            						row.gridX.view.refresh(true);
			            					}
			            				}
			            			}
			            	}
			        });
		
			    this.gridX = new Ext.grid.GridPanel
			    	({
				        width: 660,
				        height: 400,
				        loadmask: {msg: 'Carregando ...'},
				        
				        ds: this.datastore,
				        cm: new Ext.grid.ColumnModel
					    	([
						    	{header: 'Item',
						         dataIndex: 'nome',
						         sortable: true,
						         width: 200},
						        {header: 'Área',
						         dataIndex: 'group',
						         sortable: true,
						         width: 40,
						         align: 'right'}
					        ]),
				        
				        trackMouseOver: true,
				        enableColumnMove: false,
						enableColumnResize: false,
						enableDragDrop: false,
						enableHdMenu: false,
				        sm: new Ext.grid.RowSelectionModel
				        	({
				        		singleSelect: true
				        	}),
				        loadMask: true,
					    view: new Ext.grid.GroupingView
						    ({
					            forceFit: true,
					            enableRowBody: true,
					            groupTextTpl: '{text} ({[values.rs.length]} {[values.rs.length > 1 ? "Items" : "Item"]})'
					        }),
						listeners:
							{
								render: function(grid)
									{
										grid.getBottomToolbar().loading.handler = Ext.emptyFn;
									},
								rowclick: function(grid, rowIndex, e)
									{
										var item = row.gridX.getSelectionModel().getSelected().data;
										document.location.href = _PHP_.url.webroot+'admin/'+item.area+'/edit/0/'+item.id;
									}
							},
						bbar: new Ext.PagingToolbar
					        ({
					            store: this.datastore,
					            pageSize: 18,
					            displayInfo: true,
					            paramNames:
					            	{limit: 'limit',
					            	 start: 'offset'},
					            beforePageText: 'Página',
					            afterPageText: 'de {0}',
					            firstText: 'Primeira página',
					            lastText: 'Última página',
					            nextText: 'Próxima página',
					            prevText: 'Página anterior',
					            refreshText: 'Atualizar',
					            displayMsg: 'Mostrando: {0} a {1}. Total: {2}',
					            emptyMsg: 'Não ha registros no momento'
					        })
				    });
			    
			    this.fieldset = new Ext.form.FieldSet
			        ({
			            title: 'Resultado',
			            bodyStyle: 'padding: 2px',
			            autoWidth: true,
			            autoHeight: true,
						hidden: true,
			            items:
			            	[
			            		this.gridX
			            	]
			        });	 
			    
				formX.keys =
					{
					    key: Ext.EventObject.ENTER,
					    fn: this.buttons.buttons[0].handler
					};
			    formX.width = 700;
			    formX.buttons = null;
			   	formX.add(this.busca,
			   			  this.buttons,
			   			  this.fieldset);
				formX.render();
			}
	};